package com.wang.spring.config;


import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.wang.spring.handler.JustSqlHandler;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.io.IOException;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Resource
    private DataSource dataSource;

    @Bean
    public HttpMessageConverters useConverters() {
        return new HttpMessageConverters(new FastJsonHttpMessageConverter());
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        try {
            registry.addInterceptor(new JustSqlHandler(dataSource));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
